package com.wkl.config.aspects;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;

import com.wkl.domain.Result;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * controller层统一异常处理
 */
@Aspect
@Component
public class ExceptionControllerAscept {

    private Logger logger = LoggerFactory.getLogger(ExceptionControllerAscept.class);

    /**
     * 匿名切点的方式
     *
     * @param ex
     * @throws ServletException
     * @throws IOException
     */
    @AfterThrowing(value = "execution(public * com.wkl.controller..*.*(..))", throwing = "ex")
    public Result aroundAdvice(Exception ex) throws ServletException, IOException {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(500);
        result.setMsg(ex.getMessage());
        return result;
    }
}
